package com.example.t410.controller;

import com.example.t410.dao.LunTan;
import com.example.t410.dao.NootbookResult;
import com.example.t410.service.LunTanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@Slf4j
@RequestMapping("/luntan")
public class luntanController {
    @Autowired
    private LunTanService lunTanService;
//  根据类别查询
    @GetMapping("{type}")
    public NootbookResult selectType(@PathVariable String type){
        List<LunTan> lunTanList=lunTanService.selectType(type);
        log.info("查询论坛的分类为：{}",type);
        return NootbookResult.Success(lunTanList);
    }
//    发表论坛
    @PostMapping("/add")
    public NootbookResult insert(@RequestBody LunTan lunTan){
        lunTanService.insert(lunTan);
        log.info("论坛发表成功，发表人：{}",lunTan.getUserName());
        return NootbookResult.Success();
    }
//    删除论坛
    @DeleteMapping("/delete/{Id}")
    public NootbookResult delect(@PathVariable String Id){
        lunTanService.delectById(Id);
        log.info("成功删除一条论坛及其评论");
        return NootbookResult.Success();
    }



}
